﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
/// Summary description for SqlProxy
/// </summary>
public class SqlProxy
{
    private static SqlConnection MaSqlCnx = new SqlConnection();
    private static SqlCommand MaSqlCmd = new SqlCommand();


    public static List<BankAccount> getAllAccount(string user)
    {
        List<BankAccount> lstOfAccount = new List<BankAccount>();
        MaSqlCnx.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
        MaSqlCnx.Open();
        MaSqlCmd.Connection = MaSqlCnx;
        MaSqlCmd.CommandText = "select * from dbo.bank_account where user_id like '" + user+"'";
        SqlDataReader monSqlDR = MaSqlCmd.ExecuteReader();
        while (monSqlDR.Read())
        {
            string id = monSqlDR["id_account"].ToString();
            string account_name = monSqlDR["account_name"].ToString();
            DateTime create = (DateTime)monSqlDR["creation_date"];
            BankAccount ac = new BankAccount(id, account_name, create);
            lstOfAccount.Add(ac);
        }
        MaSqlCnx.Close();

        return lstOfAccount;
    }
}